package com.emergency.assist.dao;

import com.emergency.assist.domain.RouteRelation;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/*
*
 * Created by qiuyan.pei on 2020/3/12.
*/


public interface RouteRelationDao extends JpaRepository<RouteRelation, String>, JpaSpecificationExecutor<RouteRelation> {

    @Query("select count(rr) from RouteRelation rr where route.id=:routeId")
    int countByRoute(@Param("routeId") long routeId);

    @Query("select rr from RouteRelation rr where route.id=:routeId")
    List<RouteRelation> findByRoute(@Param("routeId") long routeId);

    @Query(value = "select IFNULL(sum(weight),0) as weight from bus_route_relation brr where brr.scenar_id=:scenarID and brr.route_id=:routeId",nativeQuery = true)
    Double SumWeightByScenarAndRoute(@Param("scenarID") long scenarID, @Param("routeId") Long routeId);
}
